//=============================================================================
// PepperPotAltFire - Fires darts that attract PepperPot rockets.
//=============================================================================
class PepperPotAltFire extends InstantFire;

var PepperPot Gun;

var() sound LockSound;
var() sound StabSound;

function PostBeginPlay()
{
    Super.PostBeginPlay();
    Gun = PepperPot(Owner);
}

function DoTrace(Vector Start, Rotator Dir)
{
	local Vector X, End, HitLocation, HitNormal;
	local Actor Other;
	local int Damage;

    X = vector(Dir);
    End = Start + TraceRange * X;

    Other = Trace(HitLocation, HitNormal, End, Start, true, vect(4, 4, 4));

    if(Other != None && (Other != Instigator))
    {
		if(Other.IsA('Pawn') && Pawn(Other).Health > 0)
		{
			Damage = DamageMin;

			if((DamageMin != DamageMax) && (FRand() > 0.5))
				Damage += Rand(1 + DamageMax - DamageMin);

			Damage *= DamageAtten;
			Damage *= Instigator.DamageScaling;
			Other.TakeDamage(Damage, Instigator, HitLocation, Momentum*X, DamageType);

			if(Gun.Dart != None)
				Gun.Dart.Destroy();

			Gun.Dart = Spawn(class'PepperPotDart',,, Other.Location);
			Gun.Dart.SetBase(Other);
			Gun.Dart.P = Pawn(Other);
			Gun.Dart.PlaySound(StabSound,, 0.5,, 256);
			Gun.PlaySound(LockSound, SLOT_Misc, TransientSoundVolume,,,, false);
		}
		else
		{
			if(Gun.Dart != None)
				Gun.Dart.Destroy();

			//Do a zero-extent trace to more accurately place dart.
			X = HitLocation;
			Trace(HitLocation, HitNormal, End, X, true);

			Gun.Dart = Spawn(class'PepperPotDart',,, HitLocation, rotator(End - Start));
			Gun.Dart.SetBase(Other);

			if(WeaponAttachment(Weapon.ThirdPersonActor) != None)
				WeaponAttachment(Weapon.ThirdPersonActor).UpdateHit(Other, HitLocation, HitNormal);
		}
    }
}

defaultproperties
{
     LockSound=Sound'GeneralAmbience.beep10'
     StabSound=Sound'TFMedia.Misc.Stab'
     DamageType=Class'taskforces.DamTypePepperPotDart'
     DamageMin=1
     DamageMax=1
     Momentum=1000.000000
     bWaitForRelease=True
     FireAnim="AltFire"
     FireSound=Sound'WeaponSounds.BaseFiringSounds.BPainterRifleAltFire'
     FireForce="RocketLauncherFire"
     FireRate=0.600000
     AmmoClass=Class'taskforces.PepperPotAmmo'
     ShakeRotTime=2.000000
     ShakeOffsetMag=(X=-20.000000)
     ShakeOffsetRate=(X=-1000.000000)
     ShakeOffsetTime=2.000000
     BotRefireRate=0.600000
}
